﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SpecF.Reporting;
using System.Linq.Expressions;
using SpecF.ExpressionVisitors;
using SpecF.Extensions;

namespace SpecF
{
    public class SpecF<T> : SpecBase<T>
    {
        public SpecF()
        {

        }

        public static Next<T> When(Expression<Func<T, bool>> expression)
        {
            SpecF<T> spec = NewSpec;

            if (!spec.Conditions.Any((Next<T> condition) => condition.Check.Equals(expression)))
            {
                spec.Conditions.Add(new Next<T>
                {
                    Check = expression,
                    Spec = spec,
                    ExpressionInfromatiom = expression.GetExprerssionInformation()
                });
            }

            RegisterSpec(spec);

            return spec.Conditions.First((Next<T> x) => x.Check.Equals(expression));
        }

        internal static SpecF<T> NewSpec
        {
            get { return new SpecF<T>(); }
        }

        protected internal override void ReportInternal(ReporterType reporterType)
        {
            switch (reporterType)
            {
                case ReporterType.Console:
                default:
                    this.Reporter = new ConsoleReporter<T>(this);
                    break;
                case ReporterType.Html:
                    break;
            }

            this.Reporter.Report();
        }
    }
}
